﻿using System;
using System.Data;
using System.Data.SqlClient;

public  class ViewCustomerDetailsDAL
    {
       dbConnection db = new dbConnection();

	   public void RetrieveAccountDetails(ViewCustomerDetailsBO ViewCustomerDetails)
       {
           //ViewCustomerDetailsBO ViewCustomerDetails = new ViewCustomerDetailsBO(AccountId);
        SqlConnection cn = null;
        SqlCommand cmd = null;
        int Counter = 0;

        dbConnection db = new dbConnection();
        
        try
        {
            cn = new SqlConnection();
            cn.ConnectionString = db.GetCS();

            cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "Select Customers.CustomerName,cast(Addresses.Pincode as varchar),cast(Addresses.PhoneNumber as varchar),Addresses.AddressLine1,Addresses.AddressLine2,Addresses.AddressLine3,Addresses.City,cast(Accounts.AccountId as varchar),Accounts.Amount ,Branches.BranchName,cast(Accounts.AccCreatedDate as varchar), Customers.ImagePath from Accounts,Customers,Addresses,Branches where Customers.AccountId=@AccountId and Accounts.AccountId=@AccountId and Customers.AddressId=Addresses.AddressId and Branches.BranchId=Accounts.BranchId";
			cmd.Parameters.AddWithValue("@AccountId", ViewCustomerDetails.AccountId);
               cn.Open();

               SqlDataReader rdr;


               rdr = cmd.ExecuteReader();
               while (rdr.Read())
               {
                   
                   ViewCustomerDetails.CustomerName = rdr.GetString(0);
                   ViewCustomerDetails.PinCode =Convert.ToInt64( rdr.GetString(1));
                   ViewCustomerDetails.PhoneNumber = Convert.ToInt64(rdr.GetString(2));
                   ViewCustomerDetails.AddressLine1= rdr.GetString(3);
                   ViewCustomerDetails.AddressLine2 = rdr.GetString(4);
                   ViewCustomerDetails.AddressLine3 = rdr.GetString(5);
                   ViewCustomerDetails.City = rdr.GetString(6);
                 //  ViewCustomerDetails.AccountId = (rdr.GetString(7));
                   ViewCustomerDetails.Amount =(rdr.GetDecimal(8));
                  
                   ViewCustomerDetails.Branch = rdr.GetString(9);
                   ViewCustomerDetails.AccountCreatedDate = Convert.ToDateTime(rdr.GetString(10));
                   ViewCustomerDetails.ImagePath = rdr.GetString(11);

               
               }
			rdr.Close();
	     //   Counter = cmd.ExecuteNonQuery();
               cn.Close();

               cn.Open();

              

           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message);
           }
           finally
           {
               if (cn != null)
               {
                   cn.Close();
                   cn.Dispose();
                   cn = null;
               }
           }
		//   return Counter;

       }
     
    }

